package cn.huaqingcheng.tianshu.web.view;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;
import org.springframework.http.HttpStatus;

import jakarta.annotation.Nullable;
import jakarta.validation.constraints.NotNull;

/**
 * ErrorResponse
 */
@Data
@NoArgsConstructor
@Accessors(chain = true)
@ToString(doNotUseGetters = true)
public class ErrorResponse<T> {

    private Integer code;

    private String message;

    private @Nullable T data;

    public ErrorResponse(Integer code, T data, String message) {
        this.code = code;
        this.data = data;
        this.message = message;
    }

    public static <T> ErrorResponse<T> error(@NotNull HttpStatus status, @NotNull String msg, T data) {
        return new ErrorResponse<>(status.value(), data, msg);
    }

    public static <T> ErrorResponse<T> error(int status, @NotNull String msg) {
        return new ErrorResponse<>(status, null, msg);
    }

}
